const app = getApp();
import { formatImage } from '../../utils/formatImage'

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        isTabBar: {
            type: Boolean,
            value: false
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        popStatus: false,
        bg: '',
        w: '',
        h: '',
        title: '新人专区',
        content: '这是新人礼物',
        confirmText: '领取礼物'
    },

    ready: function() {
        if (app.data.newUserPop) {
            const popStatus = app.data.newUserPop.status > 0 && !app.data.newUserPop.isClick ? true : false;

            if (app.data.newUserPop.goods_imgs.length) {
              this.setData({
                  popStatus,
                  bg: formatImage.cdnImage(app.data.newUserPop.goods_imgs[0].path, formatImage.THUMBNAIL_M),
                  w: app.data.newUserPop.goods_imgs[0].width,
                  h: app.data.newUserPop.goods_imgs[0].height
              })

              if (this.data.isTabBar && popStatus) {
                    // wx.hideTabBar({
                    //     animation: true,
                    // })
                }
            }
        } else {
            app.newUserCallback = (d) => {
                const popStatus = d.status > 0 ? true : false;

                if (app.data.newUserPop.goods_imgs.length) {
                    this.setData({
                        popStatus,
                    })

                    if (popStatus) {
                        this.setData({
                            bg: formatImage.cdnImage(d.goods_imgs[0].path, formatImage.THUMBNAIL_M),
                            w: d.goods_imgs[0].width,
                            h: d.goods_imgs[0].height
                        })
                    }
                    if (this.data.isTabBar) {
                        // wx.hideTabBar({
                        //     animation: true,
                        // })
                    }
                }
            }
        }
    },
    methods: {
        _confirmEvent() {
            app.data.newUserPop.isClick = true;
            this.setData({  
                popStatus: false
            })
            if (this.data.isTabBar) {
              wx.showTabBar({
                  animation: true,
              });
          }
            wx.navigateTo({
                url: '/pages/newcomer/newcomer',
            })
        },
        _closedEvent() {
            app.data.newUserPop.isClick = true;
            if (this.data.isTabBar) {
                wx.showTabBar({
                    animation: true,
                });
            }
            this.setData({  
                popStatus: false
            })
        }
    }
})
